<?php

declare(strict_types=1);

namespace app\admin\controller;

use app\BaseController;
use app\common\Attribute;
use think\facade\View;
use app\model\Config;

#[Attribute(title: "系统配置")]
class ConfigController extends BaseController
{
    #[Attribute(isAuth: true, isPage: true, title: "网站配置")]
    public function base()
    {
        $find = Config::select("prefix", request()->action());
        View::assign("find", $find);
        if (request()->isPost()) {
            $all = request()->param();
            $res = Config::saves($all, request()->action());
            if ($res) {
                return success("操作成功");
            } else {
                return error("操作失败");
            }
        }
        return View::fetch();
    }

    #[Attribute(isAuth: true, isPage: true, title: "邮件配置")]
    public function email()
    {
        $find = Config::select("prefix", request()->action());
        View::assign("find", $find);
        if (request()->isPost()) {
            $all = request()->param();
            $res = Config::saves($all, request()->action());
            if ($res) {
                return success("操作成功");
            } else {
                return error("操作失败");
            }
        }
        return View::fetch();
    }
}
